package com.focus.xyz.union.pages.frontend;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BasePage;
import com.focus.xyz.core.utils.prop.ConfigPropInfo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

/**
 * Created by chenmeng on 2016/3/29.
 */
public class MainPage extends BasePage {
    private Action action;
    @FindBy(xpath = "//*[@id=\"dev_username\"]")
    private WebElement username;
    @FindBy(xpath = "//*[@id=\"dev_password\"]")
    private WebElement password;
    @FindBy(xpath = "//*[@id=\"dev_login_submit\"]")
    private WebElement loginbtn;
    @FindBy(xpath = "//a[contains(text(),'忘记密码？')]")
    private WebElement forgotpass;
    @FindBy(xpath = "//a[contains(text(),'立即注册>')]")
    private WebElement reglink;
    @FindBy(xpath = "//*[@id=\"dev_toMyUnion\"]")
    private WebElement myunion;
    @FindBy(xpath = "//a[contains(text(),'退出')]")
    private WebElement logoutlink;
    @FindBy(xpath = "//a[text()='广告投放')]")
    private WebElement adsdelivery;
    @FindBy(xpath = "//a[text()='结算管理')]")
    private WebElement settleMgmt;

    private String url = null;


    public MainPage(WebDriver driver,Action action){
        super(driver,action);
        PageFactory.initElements(driver,this);
        this.action = action;
        this.url = ConfigPropInfo.UNION_FRONT_MYUNION_URL;
    }

    public void openPage() throws Exception{
        action.open(this.url);
    }

    public void clickRegisterLink() throws Exception{
        action.click(reglink);
    }
    public void inputUserName(String userName) throws Exception{
        action.inputText(this.username,userName);
    }

    public void inputPass(String pass) throws Exception{
        action.inputText(this.password,pass);
    }

    public void clickLoginBtn() throws Exception{
        action.click(loginbtn);
    }

    public void login(String username,String pass) throws Exception{
        inputUserName(username);
        inputPass(pass);
        clickLoginBtn();
    }

    public void logout() throws Exception{
        clickLogoutLink();
    }
    public void clickLogoutLink() throws Exception{
        action.click(logoutlink);
    }

    public boolean isLogined() throws Exception{
        boolean flag = false;
        if(action.isElementExsit(By.xpath("//*[@id=\"dev_login_submit\"]"))){
            flag = false;
        }else{
            flag = true;
        }
        return flag;
    }

}
